%% @author wenqi_zheng
%% @doc @todo Add description to ch_app.


-module(bank_app).
-behaviour(application).
-export([start/2, stop/1]).

%% ====================================================================
%% API functions
%% ====================================================================
-export([]).



%% ====================================================================
%% Behavioural functions
%% ====================================================================

%% start/2
%% ====================================================================
%% @doc <a href="http://www.erlang.org/doc/apps/kernel/application.html#Module:start-2">application:start/2</a>
-spec start(Type :: normal | {takeover, Node} | {failover, Node}, Args :: term()) ->
	{ok, Pid :: pid()}
	| {ok, Pid :: pid(), State :: term()}
	| {error, Reason :: term()}.
%% ====================================================================
start(_Type, _StartArgs) ->	
	io:format("Start ~p ...~n", [file:get_cwd()]),
	ok = application:start(crypto),
	ok = application:start(ranch),
	ok = application:start(cowlib),
	ok = application:start(cowboy),
	N_acceptors = 10,
	Dispatch = cowboy_router:compile(
				 [
				  {'_', [{'_', simple_web_server, []}]}
				  ]),
	cowboy:start_http(my_simple_web_server,
					  N_acceptors,
					  [{port, 8080}],
					  [{env, [{dispatch, Dispatch}]}]
					 ),	
	bank_sup:start_link(),
	{ok, self()}.

%% stop/1
%% ====================================================================
%% @doc <a href="http://www.erlang.org/doc/apps/kernel/application.html#Module:stop-1">application:stop/1</a>
-spec stop(State :: term()) ->  Any :: term().
%% ====================================================================
stop(_State) ->
	io:format("Stop ~p!", [?MODULE]),
	ok.

%% ====================================================================
%% Internal functions
%% ====================================================================


